package client

import (
	"luiz/crawler/engine"
	"luiz/crawler_distributed/config"
	"luiz/crawler_distributed/worker"
	"net/rpc"
)

func CreateProcessor(clientsChan chan *rpc.Client) engine.Processor {

	return func(request engine.Request) (engine.ParseResult, error) {
		sReq := worker.SerializeRequest(request)
		var sResult worker.ParseResult
		client := <-clientsChan
		err2 := client.Call(config.CrawlServiceRpc, sReq, &sResult)
		if err2 != nil {
			return engine.ParseResult{}, err2
		}
		return worker.DeResult(sResult), nil
	}
}
